package com.bjpower.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.bjpower.commonts.TradeStatus;
import com.bjpower.entity.TradeOrder;
import com.bjpower.mapper.TradeOrderMapper;
import com.bjpower.models.dto.KuaiQianApiDto;
import com.bjpower.models.dto.PayConfigDto;
import com.bjpower.models.dto.PaymentDto;
import com.bjpower.models.request.PayWayInfoRequest;
import com.bjpower.service.PayMentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

@Service("KUAIQIAN")
public class KuaiQianPaymentServiceImpl implements PayMentService {

    @Resource
    private TradeOrderMapper tradeOrderMapper;
    @Override
    public PaymentDto pay(PayWayInfoRequest payWayInfoRequest, PayConfigDto configDto) {
        KuaiQianApiDto kuaiQianApiDto = new KuaiQianApiDto(payWayInfoRequest,configDto);

        TradeOrder tradeOrder = new TradeOrder();
        tradeOrder.setId(IdWorker.get32UUID());
        tradeOrder.setUserNo(payWayInfoRequest.getUserNo());
        tradeOrder.setUserName(configDto.getTdpformName());
        tradeOrder.setUserOrderNo(payWayInfoRequest.getOrderNo());
        tradeOrder.setTxNo(configDto.getGatewayOrderId());
        tradeOrder.setOrderAmount(new BigDecimal(payWayInfoRequest.getOrderMoney()));
        tradeOrder.setOrderTime(new Date());
        tradeOrder.setPayProductCode(payWayInfoRequest.getPayProductCode());
        tradeOrder.setPayWayCode(payWayInfoRequest.getWayCode());
        tradeOrder.setPayWayName("快钱");
        tradeOrder.setPayTypeCode("PC_PAY");
        tradeOrder.setPayTypeName("PC支付");
        tradeOrder.setPageurl(payWayInfoRequest.getPageUrl());
        tradeOrder.setNotifyurl(payWayInfoRequest.getNotifyUrl());
        tradeOrder.setRemark("创建支付");
        tradeOrder.setEditTime(new Date());
        tradeOrder.setStatus(TradeStatus.CREATE.name());
        tradeOrderMapper.insert(tradeOrder);
        return kuaiQianApiDto;
    }
}
